//
//  WFStatus.swift
//  WangFangWeiBo
//
//  Created by 王方 on 16/7/13.
//  Copyright © 2016年 wf. All rights reserved.
//

import UIKit

class WFStatus: NSObject {
    //  发布微博时间
    var created_at: String?
    //  微博id
    var id: Int64 = 0
    //  微博内容
    var text: String?
    //  来源
    var source: String?
    //关注用户对象
    var user:WFUser?
    //转发数
    var resposts_count:Int = 0
    //评论数
    var comments_count:Int = 0
    //表态数(赞)
    var attitudes_count:Int = 0
    //转发微博对象
    var retweeted_status:WFStatus?
    //配图信息
    var pic_urls:[WFStatusPictureInfo]?
    
    //  kvc构造函数
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
        
    }
    
    //重写setvalueforkey方法
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dic = value as? [String:AnyObject] else {
                return
            }
            //代码执行到这里,肯定是dic拿到了
            user = WFUser(dic: dic)
        }else if key == "retweeted_status" {
            guard let dic = value as? [String:AnyObject] else {
                return
            }
            
            retweeted_status = WFStatus(dic: dic)
            
        }else if key == "pic_urls"{
            guard let dicArray = value as? [[String:AnyObject]] else {
                return
            }
            var tempArr = [WFStatusPictureInfo]()
            for value in dicArray{
                let pic = WFStatusPictureInfo(dic: value)
                tempArr.append(pic)
            }
            pic_urls = tempArr
            
            
        } else {
            super.setValue(value, forKey: key)
        }
    }
    
    
    //  防止字段比匹配,导致崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
